import 'package:flutter/material.dart';
import 'package:flutter_ncsjqz_getx/widget/app_bar_widget.dart';
import 'package:flutter_ncsjqz_getx/widget/base_widget.dart';
import 'package:flutter_ncsjqz_getx/widget/gradient_button.dart';
import 'package:flutter_ncsjqz_getx/widget/ink_widget.dart';
import 'package:flutter_ncsjqz_getx/widget/row_line_widget.dart';
import 'package:get/get.dart';

import 'fans_follow_logic.dart';

/// <summary>
/// todo: 粉丝、关注
/// author：zwb
/// dateTime： 2021/11/6 17:55
/// filePath： lib/page/my/fans_follow/fans_follow_view.dart
/// desc:
/// <summary>
///
class FansFollowPage extends StatefulWidget {
  final String? title;
  const FansFollowPage({this.title});
  @override
  _FansFollowPageState createState() => _FansFollowPageState();
}

class _FansFollowPageState extends State<FansFollowPage> {
  final logic = Get.put(FansFollowLogic());

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    // 1-关注 2-粉丝
    widget.title == "我的粉丝"? logic.followType = 2 : logic.followType = 1;
    logic.getData();
  }
  @override
  Widget build(BuildContext context) {
    return GetBuilder<FansFollowLogic>(
      builder: (controller) {
        return Scaffold(
          backgroundColor: Colors.white,
          appBar: appBarWidget(title: widget.title ?? ''),
          body: baseScaffoldWidget(
            onRefresh: ()async{
              print("object");
            },
            onLoad: ()async{
              print("object");
            },
            child:  ListView(
              physics: NeverScrollableScrollPhysics(),
              padding: EdgeInsets.symmetric(horizontal: 15),
              children: List.generate(logic.xList!.length, (index){
                return rowBaseWidget(
                  padding: EdgeInsets.symmetric(vertical: 10),
                  height: 70,
                  left: Expanded(
                    child: Row(
                      children: [
                        ClipOval(
                          child: InkWidget.imgNet("${logic.xList![index].userPic}",width: 50,height: 50,fit: BoxFit.cover,),
                        ),
                        SizedBox(width: 10,),
                        InkWidget.imgAsset(logic.xList![index].sex == 2 ?"girl.png":"man.png",width: 20),
                        Expanded(
                          child: InkWidget.text("${logic.xList![index].nickName}",maxLines: 2),
                        ),
                        SizedBox(width: 10,),
                      ],
                    ),
                  ),
                  // widget.title == "我的粉丝"
                  right:  SizedBox(
                    width: 100,
                    child:widget.title == "我的粉丝" ?
                    SizedBox(
                      width: 80,
                      height: 30,
                      child: gradientButton(logic.xList![index].isAttention!?"已关注":"+关注",onTap: () async{
                        if(logic.xList![index].isAttention!){
                          // 取消对粉丝的关注
                          logic.canFollw(logic.xList![index].followUserId,index);
                        }else{
                          // 关注未关注的粉丝
                          logic.setFollow(logic.xList![index].followUserId,index);
                        }
                      },bgColor: logic.xList![index].isAttention! ? Colors.grey:null),
                     ) : OutlineButton(
                        onPressed: () async{
                          // 移除我关注的用户
                          logic.canFollw(logic.xList![index].beFollowUserId,index);
                        },
                        child: InkWidget.text("取消关注",color: Colors.grey,)
                    ),
                  ),
                );
              }),
            ),
          ),
        );
      },
    );
  }

  @override
  void dispose() {
    Get.delete<FansFollowLogic>();
    super.dispose();
  }
}